#!/bin/sh -e

#DEBHELPER#

# Add the group 'jwhois' that the cache uses

addgroup --system jwhois || echo "Failed adding group \`jwhois'"

# setgid to that group. Can't do it automatically since the jwhois
# group doesn't exist until this is run, which it isn't during the
# compilation process.

if command -v suidregister >/dev/null 2>&1 && [ -e /etc/suid.conf ]; then
  suidregister -s jwhois /usr/bin/jwhois root jwhois 02755
  suidregister -s jwhois /var/cache/jwhois root jwhois 0775
elif [ -e /usr/bin/jwhois ]; then
  if chown root.jwhois /usr/bin/jwhois; then
    chmod 02755 /usr/bin/jwhois
    if chown root.jwhois /var/cache/jwhois; then
      chmod 0775 /var/cache/jwhois
    else
      echo "Failed setting ownership on cache directory - cache functions will not work."
    fi
  else
    echo "Failed setting ownership to group \`jwhois' - cache functions will not work."
  fi
fi

# Make sure the cache, if it exists, has the correct group ownership

if [ -e /var/cache/jwhois/jwhois.db.db ]; then
  chgrp jwhois /var/cache/jwhois/jwhois.db.db || echo "Failed setting ownership on cache file - cache functions will not work."
fi
